package com.woniuxy.controller;

import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.woniuxy.entity.Demand;
import com.woniuxy.entity.DisRequirements;
import com.woniuxy.entity.WareHousing;
import com.woniuxy.service.DemandService;
import com.woniuxy.utils.Result;

@Controller
@RequestMapping("/demand")
public class DemandController {
	@Autowired 
	private DemandService demandService;
	
	@RequiresPermissions("manager:find")
	@RequestMapping("/findDemand")
	@ResponseBody
	public List<Demand> findDemand(){
		return demandService.findDemand();
	}
	
	@RequiresPermissions("manager:find")
	@RequestMapping("/findDetailByOrderno")
	@ResponseBody
	public Demand findDetailByOrderno(String orderno){
		return demandService.findDetailByOrderno(orderno);
	}
	@RequiresPermissions("manager:add")
	@RequestMapping("/insert")
	@ResponseBody
	public Result<String> indertDemand(Demand demand){
		int i = demandService.insertDemand(demand);
		Result<String> result=new Result<>();
		if (i!=0) {
			result.setMessage("插入数据成功");
		}
		return result;
	}
	@RequiresPermissions("manager:update")
	@RequestMapping("/updateDemandByOrderno")
	@ResponseBody
	public Result<String> updateDemandByOrderno(Demand demand) {
		Result<String> result = new Result<>();
		int i=demandService.updateDemandByOrderno(demand);
		if (i!=0) {
			result.setMessage("更新成功");
		}
		return result;
	}
	@RequiresPermissions("manager:del")
	@RequestMapping("/delDemandByOrderno")
	@ResponseBody
	public Result<String> delDemandByOrderno(String orderno){
		Result<String> result=new Result<>();
		int i=demandService.delDemandByOrderno(orderno);
		if (i!=0) {
			result.setMessage("删除成功");
		}
		return result;
	}
	@RequiresPermissions("manager:add")
	@RequestMapping("/insertTodisRequirements")
	@ResponseBody
	public Result<String> insertTodisRequirements(DisRequirements dis){
		Result<String> result=new Result<>();
		int i=demandService.insertDisprocurement(dis);
		if (i!=0) {
			result.setMessage("提交分配成功");
		}
		return result;
	}
	@RequiresPermissions("manager:update")
	@RequestMapping("/changeStatus")
	@ResponseBody
	public Result<String> changeStatus(Demand demand){
		Result<String> result=new Result<>();
		int i=demandService.changeStatus(demand);
		if (i!=0) {
			result.setMessage("修改状态成功");
		}
		return result;
	}
	@RequiresPermissions("manager:find")
	@RequestMapping("/findWarehousing")
	@ResponseBody
	public List<WareHousing> findWarehousing(){
		return demandService.findWarehousing();
	}
}
